package com.liu.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
//配置
public class mybatisUstils {
    static SqlSessionFactory sqlSessionFactory = null;
    static {
        //扫描配置文件
        String resource = "Mybatis-config.xml";

        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //创建连接工厂
         sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }

    //获取连接
   public static SqlSession getSession() {
      return sqlSessionFactory.openSession();
   }
}
